package com.notemanagement.app;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import com.notemanagement.ui.GuideActivity;
import com.notemanagement.ui.MainActivity;
import com.notemanagement.R;

/**
 * 应用程序启动类:显示欢迎界面并跳转到主界面
 * @author king
 * @version 1.0
 * @date 2014-12-17
 */
public class AppStart extends Activity {
	
	 final AppContext ac = (AppContext) getApplication();
	 private boolean isFirstIn = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		View view = View.inflate(this, R.layout.start, null);
		setContentView(view);
		
		//渐变展示启动屏
				AlphaAnimation aa = new AlphaAnimation(0.3f,1.0f);
				aa.setDuration(2000);
				view.startAnimation(aa);
				aa.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationEnd(Animation arg0) {
						redirectTo();
					}
					
					@Override
					public void onAnimationRepeat(Animation animation) {}
					@Override
					public void onAnimationStart(Animation animation) {}
					
				});
	}
	
	private void redirectTo() {
		// TODO Auto-generated method stub
		SharedPreferences preferences = getSharedPreferences(
				"firstIn", MODE_PRIVATE);

		// 取得相应的值，如果没有该值，说明还未写入，用true作为默认值
		isFirstIn = preferences.getBoolean("isFirstIn", true);

		// 判断程序与第几次运行，如果是第一次运行则跳转到引导界面，否则跳转到主界面
		if (!isFirstIn) {
			Intent intent = new Intent(this, MainActivity.class);
			this.startActivity(intent);
			
		} else {
			Intent intent = new Intent(this, GuideActivity.class);
			this.startActivity(intent);
		}
		finish();
	}
	

}
